package cn.hbads.support.structure.tuple;

import lombok.Data;

import java.util.Objects;

/**
 * <b> Tuple- 二元元祖 </b>
 *
 * @author : yvvb
 * @date : 2025/5/04
 */
@Data
public class Tuple<T, V> {
    T value1;
    V value2;

    public Tuple(T value1, V value2) {
        this.value1 = value1;
        this.value2 = value2;
    }

    /**
     * <b>元组静态构造 </b>
     *
     * @param value1 {@link T} 元组元素1
     * @param value2 {@link V} 元组元素2
     *
     * @return {@link Tuple} 元组
     */
    public static <T, V> Tuple<T, V> of(T value1, V value2) {
        return new Tuple<>(value1, value2);
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        if (!(object instanceof Tuple<?, ?> tuple)) {
            return false;
        }
        return Objects.equals(getValue1(), tuple.getValue1()) && Objects.equals(getValue2(), tuple.getValue2());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getValue1(), getValue2());
    }
}
